package com.ptkc.constants;

/**
 * @author: Mr.Jiao
 * @date: 2018年11月07日
 */
public final class WebResult<T> {

    private WebStatus status;

    private String msg;

    private Long timestamp;

    private T data;

    public WebStatus getStatus() {
        return status;
    }

    public String getMsg() {
        return msg;
    }

    public T getData() {
        return data;
    }

    public Long getTimestamp() {
        return timestamp;
    }

    public WebResult(){
        this.timestamp = System.currentTimeMillis();
    }

    public WebResult(WebStatus status, String msg, T data) {
        this();
        this.status = status;
        this.msg = msg;
        this.data = data;
    }

    public static <T> WebResult<T> fail(WebStatus status, String msg){
        return new WebResult(status, msg, null);
    }

    public static <T> WebResult<T> fail(String msg){
        return new WebResult(WebStatus.FAIL, msg, null);
    }

    public static <T> WebResult<T> ok(String msg, T t){
        return new WebResult<>(WebStatus.SUCCESS, msg, t);
    }

    public static <T> WebResult<T> ok(T t){
        return new WebResult<>(WebStatus.SUCCESS, "ok", t);
    }

}
